package com.xmg.mgrsite.base;

import com.xmg.p2p.base.domain.SystemDictionary;
import com.xmg.p2p.base.domain.SystemDictionaryItem;
import com.xmg.p2p.base.query.SysDictQO;
import com.xmg.p2p.base.service.ISysDictService;
import com.xmg.p2p.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class SysDictController {
    @Autowired
    private ISysDictService sysDictService;

    @RequestMapping("systemDictionary_list")
    public String queryDict(@ModelAttribute("qo") SysDictQO qo, Model model) {
        model.addAttribute("pageResult", sysDictService.query(qo));
        return "systemdic/systemDictionary_list";
    }

    @RequestMapping("systemDictionary_update")
    @ResponseBody
    public JSONResult saveOrUpdateDict(SystemDictionary dict) {
        sysDictService.saveOrUpdateDict(dict);
        return new JSONResult();
    }

    @RequestMapping("systemDictionaryItem_list")
    public String queryItem(@ModelAttribute("qo") SysDictQO qo, Model model) {
        model.addAttribute("systemDictionaryGroups",sysDictService.selectAllDict());
        model.addAttribute("pageResult",sysDictService.queryItem(qo));
        return "systemdic/systemDictionaryItem_list";
    }

    @RequestMapping("systemDictionaryItem_update")
    @ResponseBody
    public JSONResult saveOrUpdateItem(SystemDictionaryItem item) {
        sysDictService.saveOrUpdateItem(item);
        return new JSONResult();
    }
}
